<?php

// +----------------------------------------------------------------------
// | Static Plugin for ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/think-plugs-static
// | github 代码仓库：https://github.com/zoujingli/think-plugs-static
// +----------------------------------------------------------------------

namespace app\api\controller;

use app\service\ai\ALiService;
use app\service\ConvertService;
use app\service\CsjDJService;
use app\service\CsjService;
use app\service\SmsService;
use app\service\XinService;
use app\xin\model\XinMember;
use think\admin\Controller;
use think\facade\Db;
use think\facade\Log;
use thans\jwt\facade\JWTAuth;
use think\facade\Session;

class IndexController extends BaseController
{
    public function chat()
    {
        $content = $this->request->post('content', '');
        $type = $this->request->post('type', 1);
        if(empty($content)){
            return jsonFail('内容不能为空');
        }
        $aliyun_ai = new ALiService();
        $data = $aliyun_ai->chat($content,$type);
        return jsonSuccess('ok',$data);
    }

    //国内快递
    public function kd(){
        $nu = $this->request->post('nu', '');
        if(empty($nu)){
            //return jsonFail('快递单号不能为空');
        }
        $uid = Session::get('uid','1');
        $ok = (new XinService())->checkUserAi($uid);
        print_r($ok);die;
        $data = (new ConvertService())->kd($nu);
        return jsonSuccess('ok',$data);
    }

    //货币列表
    public function currencyList(){
        $currency_code = $this->request->get('currency_code', '');
        $data = DB::table('xin_currency')->where('currency_code','!=',$currency_code)->order('sort')->select();
        //echo Db::getLastSql();
        return jsonSuccess('ok',$data);
    }

    //货币转换
    public function currency()
    {
        $source_code = $this->request->post('source_code', '');//源货币
        $target_code = $this->request->post('target_code', '');//目标货币
        $amount = $this->request->post('amount', '100');//金额
        if(empty($source_code) || empty($target_code)){
            return jsonFail('源货币or目标货币不能为空');
        }
        $data = (new ConvertService())->currency($source_code,$target_code,$amount);
        return jsonSuccess('ok',$data);
    }


    //文生图
    public function prompt_img(){
        $prompt = $this->request->post('prompt');
        $type = $this->request->post('type',1);
        if(empty($prompt)){
            return jsonFail('内容不能为空');
        }
        $aliyun_ai = new ALiService();
        $data = $aliyun_ai->getImgVideo($prompt,$type);
        return jsonSuccess('ok',$data);
    }

    //获取任务图片
    public function get_tasks(){
        $task_id = $this->request->get('task_id');
        if(empty($task_id)){
            return jsonFail('任务id不能为空');
        }
        $aliyun_ai = new ALiService();
        $data = $aliyun_ai->get_tasks($task_id);
        return jsonSuccess('ok',$data);
    }



}
